package com.contract.commonlib.util

import android.content.Context
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.StaggeredGridLayoutManager

/**
 * @author zhengjun
 * @desc recycleview 设置layoutmanager工具类
 * @create at 2019/6/11 13:58
 */
object RecycleviewLayoutManger {
    fun setVerticalManager(recycleview: RecyclerView, mContext: Context?) {
        val layoutManager = LinearLayoutManager(mContext)
        layoutManager.orientation = RecyclerView.VERTICAL
        recycleview.layoutManager = layoutManager
    }

    fun setHorizontalManager(recycleview: RecyclerView, mContext: Context?) {
        val layoutManager = LinearLayoutManager(mContext)
        layoutManager.orientation = RecyclerView.HORIZONTAL
        recycleview.layoutManager = layoutManager
    }

    fun setGridManagerForOne(recycleview: RecyclerView, mContext: Context?) {
        val layoutManager = GridLayoutManager(mContext, 1)
        layoutManager.orientation = RecyclerView.VERTICAL
        recycleview.layoutManager = layoutManager
    }

    fun setGridManager(recycleview: RecyclerView, mContext: Context?, count: Int) {
        val layoutManager = GridLayoutManager(mContext, count)
        recycleview.layoutManager = layoutManager
    }

    fun setStaggeredGridLayoutManager(recycleview: RecyclerView, count: Int) {
        val staggeredGridLayoutManager = StaggeredGridLayoutManager(
            count,
            StaggeredGridLayoutManager.VERTICAL
        )
        recycleview.layoutManager = staggeredGridLayoutManager
    }
}